package cn.iocoder.yudao.module.peizhen.controller.admin.withdraw;

import cn.iocoder.yudao.module.peizhen.dal.dataobject.withdraw.WithDrawAndStaffDO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.peizhen.controller.admin.withdraw.vo.*;
import cn.iocoder.yudao.module.peizhen.dal.dataobject.withdraw.WithdrawDO;
import cn.iocoder.yudao.module.peizhen.service.withdraw.WithdrawService;

@Tag(name = "管理后台 - 员工提现")
@RestController
@RequestMapping("/peizhen/withdraw")
@Validated
public class WithdrawController {

    @Resource
    private WithdrawService withdrawService;

    @PostMapping("/create")
    @Operation(summary = "创建员工提现")
    @PreAuthorize("@ss.hasPermission('peizhen:withdraw:create')")
    public CommonResult<Integer> createWithdraw(@Valid @RequestBody WithdrawSaveReqVO createReqVO) {
        return success(withdrawService.createWithdraw(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新员工提现")
    @PreAuthorize("@ss.hasPermission('peizhen:withdraw:update')")
    public CommonResult<Boolean> updateWithdraw(@Valid @RequestBody WithdrawSaveReqVO updateReqVO) {
        withdrawService.updateWithdraw(updateReqVO);
        return success(true);
    }

    @PutMapping("/check")
    @Operation(summary = "审核员工提现")
    @PreAuthorize("@ss.hasPermission('peizhen:withdraw:update')")
    public CommonResult<Boolean> checkWithdraw(@Valid @RequestBody WithdrawSaveReqVO updateReqVO) {
        withdrawService.checkWithdraw(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除员工提现")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('peizhen:withdraw:delete')")
    public CommonResult<Boolean> deleteWithdraw(@RequestParam("id") Integer id) {
        withdrawService.deleteWithdraw(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得员工提现")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('peizhen:withdraw:query')")
    public CommonResult<WithdrawRespVO> getWithdraw(@RequestParam("id") Integer id) {
        WithdrawDO withdraw = withdrawService.getWithdraw(id);
        return success(BeanUtils.toBean(withdraw, WithdrawRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得员工提现分页")
    @PreAuthorize("@ss.hasPermission('peizhen:withdraw:query')")
    public CommonResult<PageResult<WithDrawAndStaffDO>> getWithdrawPage(@Valid WithdrawPageReqVO pageReqVO) {
        PageResult<WithDrawAndStaffDO> pageResult = withdrawService.getWithdrawPage(pageReqVO);
        return success(pageResult);
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出员工提现 Excel")
//    @PreAuthorize("@ss.hasPermission('peizhen:withdraw:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportWithdrawExcel(@Valid WithdrawPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<WithdrawDO> list = withdrawService.getWithdrawPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "员工提现.xls", "数据", WithdrawRespVO.class,
//                        BeanUtils.toBean(list, WithdrawRespVO.class));
//    }

}